package cn.sw.common.database.architecture.entity;

import cn.sw.common.database.architecture.dto.query.BaseQuery;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.UUID;

/**
 * @Description: 基础实体类
 * @Author: 张众森
 * @Date: 2025/5/10
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public abstract class BaseEntity extends BaseQuery {

    // 主键id
    @TableId(value = "id", type = IdType.NONE)
    private String id;

    // 创建时间
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(value = "create_time", fill = FieldFill.INSERT)
    private Date createTime;

    // 更新时间
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(value = "update_time", fill = FieldFill.UPDATE)
    private Date updateTime;

    // 生成id
    public void generateId() {
        this.id = UUID.randomUUID().toString().replace("-", "");
    }

}
